/**
 * @class  wosh::UserGroup   
 * @brief  Defines a group of users (wosh::User)
 *
 ****************************************************************************
 * @version $Id: UserGroup.h 2863 2010-08-07 04:28:58Z alex $
 * @author  Alessandro Polo
 ****************************************************************************/
/* Copyright (c) 2007-2010, WOSH - Wide Open Smart Home 
 * by Alessandro Polo - OpenSmartHome.com
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *     * Redistributions of source code must retain the above copyright
 *       notice, this list of conditions and the following disclaimer.
 *     * Redistributions in binary form must reproduce the above copyright
 *       notice, this list of conditions and the following disclaimer in the
 *       documentation and/or other materials provided with the distribution.
 *     * Neither the name of the OpenSmartHome.com WOSH nor the
 *       names of its contributors may be used to endorse or promote products
 *       derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY Alessandro Polo ''AS IS'' AND ANY
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL Alessandro Polo BE LIABLE FOR ANY
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR UserS;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 ****************************************************************************/

#ifndef __WOSH_Core_UserGroup_H__
 #define __WOSH_Core_UserGroup_H__

 #include <woshDefs.h>
 #include <core/Object.h>
 #include <core/DataModels.h>


namespace wosh {

class UserGroup : public Object
 {
	WOSH_SERIALIZABLE(wosh::UserGroup)
	WOSH_COMPARE_RTTI(wosh::UserGroup)

	public:

		UserGroup( long id, const std::string& name ) : Object() {
			Object::setName(name);
			this->id = id;
			this->userCount = 0;
		 }

		UserGroup( const UserGroup& m ) : Object(m) {
			*this = m;
		 }

		virtual ~UserGroup() { }


//@}
/** @name Setters
 * @{
 ******************************************************************************/
	public:
		void setUserCount( long count )						{ this->userCount = count; }

//@}
/** @name Getters
 * @{
 ******************************************************************************/
	public:
		long getID() const									{ return this->id; }

		long getUserCount() const							{ return this->userCount; }

		static DataFieldCollector<UserGroup>* getDataFields() {
			DataFieldCollector<UserGroup>* fields = new DataFieldCollector<UserGroup>();
			fields->add<long, Variant>(&UserGroup::getID, "ID", 0);
			fields->add<const std::string&, Variant>(&UserGroup::getName, "Name", 1);
			fields->add<const char*, Variant>(&UserGroup::getClassName, "Type", 2);
			fields->add<const URI&,URI>(&UserGroup::getURI, "URI", 3);
			fields->add<long, Variant>(&UserGroup::getUserCount, "Users", 4);
			return fields;
		 }


//@}
/** @name Operators Overloading
 * @{
 ******************************************************************************/
	public:
		virtual UserGroup& operator=(const UserGroup& m) {
			(Object&)*this = (const Object&)m;
			this->id = m.id;
			this->userCount = m.userCount;
			return *this;
		 }

		virtual bool operator==(const UserGroup &other) const {
			if ( this->id != other.id )
				return false;
			
			return true;
		 }

		virtual bool operator!=(const UserGroup &other) const	{ return !(*this == other);  }

//@}
/** @name Serialization interface
 * @{
 ******************************************************************************/
	public:
		virtual std::string toString() const				{ return Utilities::format("%ld:%s", getID(), getName().c_str()); }
		virtual bool updateHash( DataHashContext* hash_context ) const {
			if ( hash_context == NULL ) return false;
			bool ret = true;
			ret = hash_context->update( this->id ) & ret;
			ret = hash_context->update( this->userCount ) & ret;
			return ret;
		 }

//@}
	protected:
		long id;			///< Unique ID of the group
		long userCount;		///< number of users

}; // class def

}; // namespace wosh

#endif //__WOSH_Core_UserGroup_H__
